package com.wfs.suanfa.leet;

/**
 * 循环队列实现
 */
public class CircularQueue {
    //数组
    private String[] items;
    private int n=0;
    //头尾下标
    private int head=0;
    private int tail=0;

    //申请一个大小为capacity数组
    public CircularQueue(int capacity){
        items=new String[capacity];
        n=capacity;
    }
    //入队
    public boolean enqueue(String item){
        if ((tail+1)%n==head) return true;
        items[tail]=item;
        tail=(tail+1)%n;
        return true;
    }

    /**
     * 出队
     */
    public String dequeue(String item){
        if (head==tail) return null;
        String item1 = items[head];
        head=(head+1)%n;
        return item1;
    }
}
